
#import <Cocoa/Cocoa.h>
#import <AudioUnit/AudioUnit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <DDHidLib/DDHidLib.h>


#import "ButtonState.h"

#define JOYSTICK_AXISMAX 0xFFFF
#define JOYSTICK_AXISOFFSET JOYSTICK_AXISMAX/2


typedef enum
{
	kNoSelection,
	kSelectedSource,
	kSelectedSpeaker
} SelectionType;

@interface UDMOctogris_XYView : NSView
{
    AudioUnit 				mAU;
    AUParameterListenerRef	mParameterListener;
	
	int						mNumberOfSources;
	int						mNumberOfSpeakers;
	
	NSPoint					*mDummyPositions; //battling against memory ovverwrites here...
	
	NSPoint					*mSourcePositions;
	NSPoint					*mSourcePositionsDown;
	float					*mSourceAngularOrder;
	float					*mSourceDistances;
	float					*mOldSourceDistances;
	
	NSPoint					*mSpeakerPositions;
	float					*mSpeakerAttenuations;
	BOOL					*mSpeakerMutes;
	
	NSImage					*mBackground;
	NSDictionary			*mTextAttributes1;
	NSDictionary			*mTextAttributes2;
	
	SelectionType			mSelectionType;
	int						mSelectedItem;
	
	BOOL					mShowGridLines;
	int						mMovementMode;
	
	int						mShowLevels;
	BOOL					mTakeAttenuation;
	BOOL					mEnableJoystick;
	BOOL					mLinkMovement;
	BOOL					mLinkDistance;
		
	//=========\/\/\/JOYSTICK STUFF\/\/\/=======
	IBOutlet NSArrayController * mJoysticksController;
	
	NSArray * mJoysticks;
	NSMutableArray * mJoystickButtons;
	//	BOOL buttonstates[MAX_JOYBUTTS] = {FALSE};
	float mXAxis;
	float mYAxis;
	// Min and max values for auto-calibration. Initialized
	// to opposite extremes so that joystick input guaranteed
	// to overwrite the value.
	int maxXAxis;
	int minXAxis;
	int maxYAxis;
	int minYAxis;
	NSInteger mJoystickIndex;
	DDHidJoystick * mCurrentJoystick;
	//============^^^JOYSTICK STUFF^^^==========
}

- (void)setShowLevels:(UInt32)s;
- (void)setTakeAttenuation:(BOOL)t;

- (void)setAU:(AudioUnit)inAU;
- (void)setShowGridLines:(BOOL)showGridLines;
- (void)setMovementMode:(int)m;
- (void)setEnableJoystick:(BOOL)enableJoystick;
- (void)setLinkMovement:(BOOL)linkMovement;
- (void)setLinkDistance:(BOOL)linkDistance;
- (void)changeDist:(int)s
		   inValue:(float)value;

- (void)startLinkedMove:(BOOL)duringMove;
- (void)endLinkedMove;
- (void)continueLinkedMove;

- (void)_synchronizeUIWithParameterValues;
- (void)_addListeners;
- (void)_removeListeners;
- (void)_parameterListener:(void *)inObject parameter:(const AudioUnitParameter *)inParameter value:(Float32)inValue;

//=========\/\/\/JOYSTICK STUFF\/\/\/=======
- (NSArray *) joysticks;
- (NSArray *) joystickButtons;
- (unsigned) joystickIndex;
- (void) setJoysticks: (NSArray *) theJoysticks;
- (void) setJoystickIndex: (NSInteger) theJoystickIndex;
- (int) xAxis;
- (int) yAxis;
//============^^^JOYSTICK STUFF^^^==========


//=========\/\/\/JOYSTICK STUFF\/\/\/=======
- (void) ddhidJoystick: (DDHidJoystick *)  joystick
                 stick: (unsigned) stick
              xChanged: (int) value;

- (void) ddhidJoystick: (DDHidJoystick *)  joystick
                 stick: (unsigned) stick
              yChanged: (int) value;

- (void) ddhidJoystick: (DDHidJoystick *) joystick
                 stick: (unsigned) stick
             otherAxis: (unsigned) otherAxis
          valueChanged: (int) value;

- (void) ddhidJoystick: (DDHidJoystick *) joystick
            buttonDown: (unsigned) buttonNumber;

- (void) ddhidJoystick: (DDHidJoystick *) joystick
              buttonUp: (unsigned) buttonNumber;
//============^^^JOYSTICK STUFF^^^==========

@end
